﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Authentication.Configuration
{
    public static class SystemConfiguration
    {
        private static int defaultPageSize = 0;
        public static int DefaultPageSize
        {
            get
            {
                if (defaultPageSize > 0) return defaultPageSize;
                int.TryParse(ConfigurationManager.AppSettings["DefaultPageSize"], out defaultPageSize);
                if (defaultPageSize <= 0) defaultPageSize = 20;
                return defaultPageSize;
            }
        }


        private static string connectionString;
        public static string ConnectionString
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(connectionString)) return connectionString;
                connectionString = ConfigurationManager.AppSettings["ConnectionString"];
                if (string.IsNullOrWhiteSpace(connectionString)) return "DefaultConnection";
                return connectionString;
            }
        }


        private static string schema;
        public static string Schema
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(schema)) return schema;
                var key = ConfigurationManager.AppSettings.AllKeys.FirstOrDefault(x => x.ToUpper() == "SCHEMA");
                if (!string.IsNullOrEmpty(key)) schema = ConfigurationManager.AppSettings[key];
                if (string.IsNullOrWhiteSpace(schema)) return "dbo";
                schema = schema.ToUpper();
                return schema;
            }
        }
    }
}
